package com.vma.suggestion.service;

import com.vma.shoes.bizModel.model.Article;

import java.util.Date;
import java.util.List;

/**
 * Created by chenzui on 2017/5/4.
 */
public class ArticleService {
    public static void addArticle(String title,String simpleDesc,String url,String content){
        new Article().setStatus("1").setContent(content).setArticleName(title).setCreateTime(new Date())
                .setSimpleDesc(simpleDesc).setImgUrl(url).setIfDelete("0").save();
    }

    public static List<Article> qryArticleList(){
        return Article.dao.find("SELECT * FROM article WHERE if_delete = 0 and status = 1 ORDER BY create_time DESC ");
    }

    public static List<Article> qryArticles(){
        return Article.dao.find("SELECT * FROM article WHERE if_delete = 0  ORDER BY create_time DESC ");
    }

    public static void update(Integer id){
        Article article =  Article.dao.findById(id);
        article.setStatus(article.getStatus().equals("1")?"0":"1").update();
    }

    public static void delete(Integer id){

        Article.dao.findById(id).setIfDelete("1");
    }

    public static Article getArticleById(Integer articleId){
        return Article.dao.findById(articleId);
    }
}
